﻿using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;

namespace Plot.Primitives
{
    internal class Visitor
    {
        private readonly Canvas canvas;

        public Visitor(Canvas canvas)
        {
            this.canvas = canvas;
        }

        public void Clear()
        {
            canvas.Children.Clear();
        }

        public void Process(PShape shape)
        {
            foreach (dynamic s in shape)
                Visit(s);
        }

        public void Visit(PLine line)
        {
            var dline = new Line {
                                     X1 = line.StartPoint.X,
                                     Y1 = line.StartPoint.Y,
                                     X2 = line.EndPoint.X,
                                     Y2 = line.EndPoint.Y,
                                     Stroke = new SolidColorBrush(Colors.Black),
                                     StrokeThickness = 2,
                                     RenderTransform = new RotateTransform {
                                                                               Angle = line.Angle,
                                                                               CenterX = line.PivotPoint.X,
                                                                               CenterY = line.PivotPoint.Y } };

            canvas.Children.Add(dline);
        }

        public void Visit(AxisArrow arrow)
        {
            Process(arrow);
        }

        public void Visit(Axis axis)
        {
            Process(axis);
        }

        public void Visit(AxisDivider divider)
        {
            Process(divider);
        }

        public void Visit(XYPlot plot)
        {
            Process(plot);
        }

        public void Visit(XYDataShape data)
        {
            Process(data);
        }
    }
}